import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger';
import { writeFileSync } from 'fs';

async function bootstrap() {
  const app = await NestFactory.create(AppModule);
  const config = new DocumentBuilder()
    .setTitle('NestJS')
    .setDescription('The simple Todo API description for My NestJS Demo')
    .setVersion('1.0')
    .build();
  const document = SwaggerModule.createDocument(app, config);
  writeFileSync('./swagger.json', JSON.stringify(document));
  SwaggerModule.setup('api-docs', app, document); // 文档访问地址是 http://localhost:3000/api
  await app.listen(process.env.PORT ?? 3000);
}
bootstrap().catch((err) => console.error(err));
